package com.fruitshop.controller;

import com.fruitshop.common.Result;
import com.fruitshop.dto.BannerDTO;
import com.fruitshop.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 轮播图控制器
 */
@RestController
@RequestMapping("/banner")  // 完整路径为/api/banner
public class BannerController {
    
    @Autowired
    private BannerService bannerService;
    
    /**
     * 获取所有轮播图
     */
    @GetMapping("/list")
    public Result<List<BannerDTO>> getAllBanners() {
        try {
            List<BannerDTO> banners = bannerService.getAllActiveBanners();
            return Result.success("获取轮播图成功", banners);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(500, "获取轮播图失败: " + e.getMessage());
        }
    }
} 